package skean.yzsm.com.androidvideocache;

import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;

import java.io.File;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private String v1 = "http://118.193.152.103:9090/plugins/yzapi/v1/files/download/20170810/0ad30d73de3540abaade9f5742367be1.mp4";
    private String v2 = "http://118.193.152.103:9090/plugins/yzapi/v1/files/download/20170810/5ff576266ccc4822a0284740576c6758.mp4";
    private String v3 = "http://118.193.152.103:9090/plugins/yzapi/v1/files/download/20170810/81c8fddbf8294ac085b34f0363b12385.mp4";
    private String v4 = "http://118.193.152.103:9090/plugins/yzapi/v1/files/download/20170810/a5723c010924467b934e3202dd7e6365.mp4";
    private String v5 = "http://118.193.152.103:9090/plugins/yzapi/v1/files/download/20170814/0af4fb97b2d644c0b7821128e8fd04eb.mp4";
    private String v6 = "http://118.193.152.103:9090/plugins/yzapi/v1/files/download/20170814/7310f256f4304a93b5a00feeefcb89e9.mp4";
    private String v7 = "http://118.193.152.103:9090/plugins/yzapi/v1/files/download/20170818/fd5ee9346ff84191b6de2bafb042ec48.mp4";
    private Button btnVideo1;
    private Button btnVideo2;
    private Button btnVideo3;
    private Button btnVideo4;
    private Button btnVideo5;
    private Button btnVideo6;
    private Button btnVideo7;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        btnVideo1.setOnClickListener(this);
        btnVideo2.setOnClickListener(this);
        btnVideo3.setOnClickListener(this);
        btnVideo4.setOnClickListener(this);
        btnVideo5.setOnClickListener(this);
        btnVideo6.setOnClickListener(this);
        btnVideo7.setOnClickListener(this);
    }

    private void initView() {
        btnVideo1 = (Button) findViewById(R.id.btnVideo1);
        btnVideo2 = (Button) findViewById(R.id.btnVideo2);
        btnVideo3 = (Button) findViewById(R.id.btnVideo3);
        btnVideo4 = (Button) findViewById(R.id.btnVideo4);
        btnVideo5 = (Button) findViewById(R.id.btnVideo5);
        btnVideo6 = (Button) findViewById(R.id.btnVideo6);
        btnVideo7 = (Button) findViewById(R.id.btnVideo7);
    }

    @Override
    public void onClick(View v) {
        String url = null;
        switch (v.getId()) {
            case R.id.btnVideo1:
                url = v1;
                break;
            case R.id.btnVideo2:
                url = v2;
                break;
            case R.id.btnVideo3:
                url = v3;
                break;
            case R.id.btnVideo4:
                url = v4;
                break;
            case R.id.btnVideo5:
                url = v5;
                break;
            case R.id.btnVideo6:
                url = v6;
                break;
            case R.id.btnVideo7:
                url = v7;
                break;
        }
        Intent intent = new Intent(getBaseContext(), CachedVideoViewActivity.class).putExtra(CachedVideoViewActivity.EXTRA_VIDEO_URL, url)
                                                                                   .putExtra(CachedVideoViewActivity.EXTRA_DEST_DIR,
                                                                                             new File(Environment.getExternalStorageDirectory(),
                                                                                                      "CacheTest").getAbsolutePath())
                                                                                   .putExtra(CachedVideoViewActivity.EXTRA_AUTHORIZATION,
                                                                                             "Basic c2tlYW46MTIzNDU2");
        startActivity(intent);
    }
}
